package com.tjx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tjx.entity.Performance;
import com.tjx.mapper.PerformanceMapper;
import com.tjx.service.IPerformanceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 演出表 服务实现类
 * </p>
 *
 * @author tjx
 * @since 2025-10-29
 */
@Service
public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Performance> implements IPerformanceService {
    @Autowired
    private PerformanceMapper performanceMapper;
    /**
     * 查询所有演出
     */
    @Override
    public List<Performance> performanceQueryAll() {
        QueryWrapper<Performance> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_deleted", 0);
        return performanceMapper.selectList(queryWrapper);
    }

    /**
     * 新增演出
     */
    @Override
    public Integer performanceAdd(Performance performance) {
        performance.setCreateDate(LocalDate.now());
        performance.setUpdateDate(LocalDate.now());
        performance.setIsDeleted(0);
        Integer row1 = performanceMapper.insert(performance);
        if(row1 > 0){
            performance.setPerformanceId("performance" + performance.getId());
            Integer row2 = performanceMapper.updateById(performance);
            return row2;
        }
        return row1;
    }

    /**
     * 删除演出
     */
    @Override
    public Integer performanceDelete(Performance performance) {
        performance.setIsDeleted(1);
        performance.setUpdateDate(LocalDate.now());
        return performanceMapper.updateById(performance);
    }

    /**
     * 更新演出
     */
    @Override
    public Integer performanceUpdate(Performance performance) {
        performance.setUpdateDate(LocalDate.now());
        return performanceMapper.updateById(performance);
    }
}
